package com.example.bill.adapter;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import com.example.bill.application.BillApplication;
import com.example.bill.entity.Memo;
import com.example.bill.fragment.BillListFragment;
import com.example.bill.repository.MemoRepository;

import java.time.LocalDate;
import java.util.List;
import java.util.function.Function;

public class BillListAdapter extends FragmentPagerAdapter {

    private final Function<Integer, LocalDate> position2LocalDate;

    public BillListAdapter(@NonNull FragmentManager fm, Function<Integer, LocalDate> position2LocalDate) {
        super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
        this.position2LocalDate = position2LocalDate;

    }

    @NonNull
    @Override
    public Fragment getItem(int position) {

        LocalDate date = position2LocalDate.apply(position);

        return BillListFragment.newInstance(date.getYear(), date.getMonthValue());
    }

    @Override
    public int getCount() {
        return 20;
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {

        LocalDate date = position2LocalDate.apply(position);

        return date.getMonthValue()+"月份";
    }


}
